<?php
	class hinhthuclanhlaidb
	{
		public function Them($MaHTLanhLai = 0, $TenHTLanhLai = "", $ThoiGianLanhLai = 0)
		{
			$sql = "INSERT INTO hinhthuclanhlai(MaHTLanhLai, TenHTLanhLai, ThoiGianLanhLai)
					VALUES($MaHTLanhLai, '$TenHTLanhLai', $ThoiGianLanhLai)";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function TonTaiTrongSoTietKiem($MaHTLanhLai = 0)
		{
			$sql = "SELECT * FROM sotietkiem WHERE 1";
			if($MaHTLanhLai > 0)
				$sql.= " AND MaHTLanhLai = $MaHTLanhLai";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function CapNhat($MaHTLanhLai = 0, $TenHTLanhLai = "", $ThoiGianLanhLai = 0)
		{
			$sql = "UPDATE hinhthuclanhlai 
					SET TenHTLanhLai = '$TenHTLanhLai',
						ThoiGianLanhLai = '$ThoiGianLanhLai'
					WHERE MaHTLanhLai = $MaHTLanhLai";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Xoa($MaHTLanhLai = 0)
		{
			$sql = "DELETE FROM hinhthuclanhlai 
					WHERE MaHTLanhLai = $MaHTLanhLai";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function XoaTatCa()
		{
			$sql = "DELETE FROM hinhthuclanhlai";			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($MaHTLanhLai = 0, $TenHTLanhLai = "", $ThoiGianLanhLai = 0)
		{
			$sql = "SELECT * 
					FROM hinhthuclanhlai 
					WHERE 1";
			
			if($MaHTLanhLai > 0)
				$sql .= " AND MaHTLanhLai = $MaHTLanhLai";
				
			if($TenHTLanhLai != "")
				$sql .= " AND TenHTLanhLai = '$TenHTLanhLai'";
			
			if($ThoiGianLanhLai > 0)
				$sql .= " AND ThoiGianLanhLai = $ThoiGianLanhLai";
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
	}
?>